package com.aiyige.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by zhuyakun on 2017/11/3.
 */

public class ListUtil {

    public static boolean isEmpty(List<?> list) {
        return list == null || list.isEmpty();
    }

    public static <T> T getFirstItem(List<T> list) {
        if (ListUtil.isEmpty(list)) return null;
        return list.get(0);
    }

    public static <T> T getRandomItem(List<T> list) {
        if (ListUtil.isEmpty(list)) return null;
        int size = list.size();
        int randomIndex = new Random().nextInt(size);
        return list.get(randomIndex);
    }

    public static <T> ArrayList<T> covertToArrayList(List<T> source) {
        ArrayList<T> result = new ArrayList<>();
        if (source == null) return result;
        result.addAll(source);
        return result;
    }


}
